using System;
using System.Windows.Forms;
using System.Collections;

class ServerItemsComparer : IComparer
{
    private int col;
    private bool rev;
    public ServerItemsComparer()
    {
        col = 0;
        rev = false;
    }
    public ServerItemsComparer(int column, bool reverse)
    {
        col = column;
        rev = reverse;
    }
    public int Compare(object x, object y)
    {
        ListViewItem item1 = (ListViewItem)x;
        ListViewItem item2 = (ListViewItem)y;
        int result = 0;

        switch (col)
        {
            case 0:
                result=String.Compare(item1.SubItems[0].Text, item2.SubItems[0].Text);
                break;
                
            case 1:
                int i1 = Convert.ToInt32(item1.SubItems[1].Text);
                int i2 = Convert.ToInt32(item2.SubItems[1].Text);
                if(i1<i2)
                    result= -1;
                else 
                  if(i1 == i2)
                    result= 0;
                  else
                    result=1;
                break;

            case 2:
                result=String.Compare(item1.SubItems[2].Text, item2.SubItems[2].Text);
                break;

            case 3:
                result=String.Compare(item1.SubItems[3].Text, item2.SubItems[3].Text);
                break;            
        }
        if (rev)
            result = -result;
        return result;
    }
}
